package com.fast.security;

import com.fast.service.SysUserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author ruan cai yuan
 * @version 1.0
 * @fileName com.fast.security.UserDetailsServiceImpl
 * @description: TODO
 * @since 2024/6/23 16:15
 */
@Component
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private SysUserService userService;

    /**
     * 根据用户名加载用户的信息让spring托管
     * UserDetails,可以用user默认实现,也可自定义
     *
     * @param username 用户名称
     * @return 用户详细信息（注入全局）
     * @throws UsernameNotFoundException 用户账号不存在异常
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return userService.loadUserByUsername(username);
    }
}
